package com.aviccxzx.smarthome.UserModule;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.aviccxzx.smarthome.R;
import com.aviccxzx.smarthome.base.GosUserModuleBaseActivity;
import com.aviccxzx.smarthome.utils.CodeUtils;


/**
 * Created by joey on 2016/10/25.
 */
public class CamShareActivity extends GosUserModuleBaseActivity implements View.OnClickListener {
    ImageView camshare_img;
    Bitmap mBitmap;
    String share = "";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setContentView(R.layout.camshare_share_lay_v19);
        }else {
        }

        initView();
    }

    private void initView() {
        ((TextView) findViewById(R.id.title_tv)).setText("摄像机分享");
        findViewById(R.id.ll_title_left_view).setOnClickListener(this);
        findViewById(R.id.title_right_text).setVisibility(View.VISIBLE);
        ((TextView) findViewById(R.id.title_right_text)).setText("分享记录");
        findViewById(R.id.title_right_text).setOnClickListener(this);
        camshare_img=(ImageView)findViewById(R.id.camshare_img);
        share = getIntent().getStringExtra("yst");
        if(!TextUtils.isEmpty(share)){
            //生成二维码
            WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
            int width = wm.getDefaultDisplay().getWidth();
            mBitmap = CodeUtils.createImage("cameraShare:"+share, width/2, width/2, null);
            camshare_img.setImageBitmap(mBitmap);
        }else {
            //提示获取分享设备列表失败
            showToast("二维码生成失败");
        }
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ll_title_left_view:
                finish();
                break;
            case R.id.title_right_text:
                Intent intent = new Intent(this,ShareCamrecordActivity.class);
                intent.putExtra("yst",share);
                startActivity(intent);
                break;
        }
    }
}
